//
// * Copyright (c) 2002-2009 "Neo Technology,"
// *     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// * This file is part of Neo4j.
// * 
// * Neo4j is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Affero General Public License as
// * published by the Free Software Foundation, either version 3 of the
// * License, or (at your option) any later version.
// * 
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Affero General Public License for more details.
// * 
// * You should have received a copy of the GNU Affero General Public License
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
namespace org.neo4j.kernel.impl.util
{

	using Test = junit.framework.Test;
	using TestCase = junit.framework.TestCase;
	using TestSuite = junit.framework.TestSuite;

	using ArrayIntSet = org.neo4j.kernel.impl.util.ArrayIntSet;

	public class TestArrayIntSet : TestCase
	{
		public TestArrayIntSet(string testName) : base(testName)
		{
		}

		static void Main(string[] args)
		{
			junit.textui.TestRunner.run(suite());
		}

		public static Test suite()
		{
			TestSuite suite = new TestSuite(typeof(TestArrayIntSet));
			return suite;
		}

		public virtual void setUp()
		{
		}

		public virtual void tearDown()
		{
		}

		public virtual void testArrayIntSet()
		{
			ArrayIntSet @set = new ArrayIntSet();

			@set.Add(1);
			@set.Add(2);
			@set.Add(3);
			@set.Add(4);
			@set.Add(5);
			@set.Add(6);
			@set.Add(7);
			@set.Add(8);
			@set.Add(9);
			@set.Add(10);

			int count = 0;
			foreach (int value in @set.values())
			{
				assertTrue(@set.Contains(value));
				count++;
			}
			assertEquals(10, count);

			assertTrue(@set.Remove(2));
			assertTrue(@set.Remove(9));
			assertTrue(@set.Remove(5));
			assertTrue(!@set.Remove(2));
			assertTrue(!@set.Remove(9));
			assertTrue(!@set.Remove(5));

			count = 0;
			foreach (int value in @set.values())
			{
				assertTrue(@set.Contains(value));
				count++;
			}
			assertEquals(7, count);

			assertTrue(@set.Remove(3));
			assertTrue(@set.Remove(8));
			assertTrue(@set.Remove(4));
			assertTrue(!@set.Remove(3));
			assertTrue(!@set.Remove(8));
			assertTrue(!@set.Remove(4));

			count = 0;
			foreach (int value in @set.values())
			{
				assertTrue(@set.Contains(value));
				count++;
			}
			assertEquals(4, count);

			assertTrue(@set.Remove(1));
			assertTrue(@set.Remove(7));
			assertTrue(@set.Remove(6));
			assertTrue(!@set.Remove(1));
			assertTrue(!@set.Remove(7));
			assertTrue(!@set.Remove(6));

			count = 0;
			foreach (int value in @set.values())
			{
				assertTrue(@set.Contains(value));
				count++;
			}
			assertEquals(1, count);

			assertTrue(@set.Remove(10));
			assertTrue(!@set.Remove(10));

			count = 0;
			foreach (int value in @set.values())
			{
				assertTrue(@set.Contains(value));
				count++;
			}
			assertEquals(0, count);
		}

		public virtual void testContains()
		{
			ArrayIntSet @set = new ArrayIntSet();
			for (int i = 0; i < 10; i++)
			{
				@set.Add(i);
				assertTrue(@set.Contains(i));
			}
			for (int i = 0; i < 10; i++)
			{
				assertTrue(@set.Contains(i));
			}
			for (int i = 0; i < 10; i+=2)
			{
				@set.Remove(i);
				assertTrue(!@set.Contains(i));
			}
			for (int i = 0; i < 10; i++)
			{
				if (i % 2 == 0)
				{
					assertTrue(!@set.Contains(i));
				}
				else
				{
					assertTrue(@set.Contains(i));
				}
			}

			for (int i = 0; i < 1000; i++)
			{
				@set.Add(i);
				assertTrue(@set.Contains(i));
			}
			for (int i = 0; i < 1000; i++)
			{
				assertTrue(@set.Contains(i));
			}
			for (int i = 0; i < 1000; i+=2)
			{
				@set.Remove(i);
				assertTrue(!@set.Contains(i));
			}
			for (int i = 0; i < 1000; i++)
			{
				if (i % 2 == 0)
				{
					assertTrue(!@set.Contains(i));
				}
				else
				{
					assertTrue(@set.Contains(i));
				}
			}
		}
	}
}